var map = new GMap(document.getElementById("map"));
map.addControl(new GLargeMapControl());
map.addControl(new GMapTypeControl());
map.centerAndZoom(new GPoint(138.599981, -34.928615), 7);

//define rest of icon (except .image which is node dependent)
var baseIcon = new GIcon();
baseIcon.image = "http://labs.google.com/ridefinder/images/mm_20_red.png";
baseIcon.shadow = "http://labs.google.com/ridefinder/images/mm_20_shadow.png";
baseIcon.iconSize = new GSize(12, 20);
baseIcon.shadowSize = new GSize(22, 20);
baseIcon.iconAnchor = new GPoint(6, 20);
baseIcon.infoWindowAnchor = new GPoint(5, 1);

function createMarker(point,html, iconfilename)
{
        baseIcon.image = "http://labs.google.com/ridefinder/images/" + iconfilename + ".png";
        var icon = new GIcon(baseIcon);
        var marker = new GMarker(point, icon);

        GEvent.addListener(marker, "click", function()
        {
                marker.openInfoWindowHtml(html);
        });
        
        return marker;
}

<?

//grab data from database
$result = mysql_query("SELECT * FROM nodes",$link);

//state if no results
if (!$result)
{
	echo "no results ";
}

//otherwise read back the data
else while($row = mysql_fetch_array($result))
{
               //create the point
               echo "var point = new GPoint(" . $row['lon'] . "," . $row['lat'] . ");\n";

               //format out string to appear in popup bubble
               $myhtml = "'Node ". $row['id'] . " - " .  $row['name'] . "";

//GIVE MODIFY LINK IF OWNERID=loggedinid eg this is one of your nodes
if($session->username == $row['ownerid'])
{
               $myhtml .= "<p></p><a href=\"modifyuser.php?searchid=" . $row['id'] . "\">Modify</a>";
}
               $myhtml .= "<p></p><a href=\"javascript:void(0);\"" . $row['id'] . "\"";
               $myhtml .= "onClick=\"window.open(\'displaynode.php?id=" . $row['id']. "\',\'mywindow\',\'width=400,height=400\')\" ";
               $myhtml .= ">Details</a>";
               $myhtml .= "'";

               //work out the icon suffix depending on status
               if($row['status'] == 1)
               {
                       $iconfilename="'mm_20_blue'";
               }
               else
               {
                       $iconfilename="'mm_20_red'";
               }

               //create the marker
               //echo ("var marker" . $row['id'] . " = createMarker(point, $myhtml,$iconfilename);\n");
 
              //check if want this node to be draggable
              //check if current row id is same as our specified draggable node
              if($row['id'] ==  $draggablenode)
              {
                //format .icon url
                echo ("baseIcon.image =\"http://labs.google.com/ridefinder/images/mm_20_green.png\"\n");
                echo ("var marker" . $row['id'] . " = new GMarker(point,{icon:baseIcon, draggable: true} )\n");
                //add marker to map
                echo "map.addOverlay(marker" . $row['id'] . ");\n";
                
                echo("marker". $row['id']. ".enableDragging(); \n");
                echo("GEvent.addListener(marker" . $row['id'] .", \"drag\",function(){ \n");
                echo("document.getElementById(\"ulat\").value=marker" . $row['id']. ".getPoint().lat();\n");
                echo("document.getElementById(\"ulong\").value=marker" .$row['id'] . ".getPoint().lng();\n");
                echo "}\n";
                echo ");\n";

                echo("GEvent.addListener(marker" . $row['id'] . ", \"click\",function() {marker.openInfoWindowHtml(html);})\n");
              }
             
             //otherwise create normal marker
             else
             {
                echo("var marker = createMarker(point,$myhtml, $iconfilename);");
                add marker to map
                echo "map.addOverlay(marker);\n";
             }
               //neaten up html code
               echo "\n";

}

//close off database connection
mysql_close($link);

?>